<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="con"></div>
    <div class="box"></div>
    <script src="./axios.min.js"></script>
    <script>
        var zhou = ['欧洲', '亚洲', '大洋洲', '非洲', '北美洲', '南美洲'];
        var guojia = [];
        var oCon = document.querySelector('.con');
        var oBox = document.querySelector('.box');
        //使用 js将 洲的 内容添加到 页面上
        var zhoustr = "";
        for (let i = 0; i < zhou.length; i++) {
            zhoustr += `<button>${zhou[i]}</buttton>`;
        }
        oCon.innerHTML = zhoustr;

        //获取数据的初始值
        getData(zhou[0]);

        var aBtn = document.querySelectorAll('button');
        for (let i = 0; i < aBtn.length; i++) {
            aBtn[i].onclick = function () {
                console.log(this.innerHTML);
                getData(this.innerHTML);
            }
        }


        function getData(guojiaName) {
            //获取数据
            axios.get(`http://www.51houniao.com/requirement/destination/countries/${guojiaName}`).then(res => {
                console.log(res);
                //解构
                var { data } = res;
                var guojiastr = '';
                data.forEach(item => {
                    guojiastr += `<span>${item.country}</span>`
                });
                oBox.innerHTML = guojiastr;
            })
        }
    </script>

</body>

</html>